package avicit.bdp.dgs.qa.rest;

import avicit.bdp.common.database.ColumnMeta;
import avicit.bdp.common.database.TableMeta;
import avicit.bdp.dgs.qa.service.BdpDgsDatasourceService;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2023-04-24
 * @类说明：BdpDgsDatasourceRest
 * @修改记录：
 * @注意事项：
 * @主要功能：数据质量数据源Rest接口
 */
@RestController
@Api(tags = "qa", description = "质量作业Rest接口")
@RequestMapping("/api/bdp/dgs/qa/datasource")
public class BdpDgsDatasourceRest {
    @Autowired
    private BdpDgsDatasourceService dgsDsService;

    /**
     * 根据数据源ID查询dbName
     * @param datasourceId 数据源ID
     * @return
     */
    @GetMapping("/dbName")
    @ApiOperation(value = "根据数据源ID查询dbName")
    public ResponseMsg<List<String>> getDbName(
            @ApiParam(value = "数据源ID", name = "datasourceId") @RequestParam String datasourceId) {
        ResponseMsg<List<String>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.dgsDsService.getDbName(datasourceId));

        return responseMsg;
    }

    /**
     * 根据数据源ID查询表
     * @param datasourceId 数据源ID
     * @return
     */
    @GetMapping("/tableList")
    @ApiOperation(value = "根据数据源ID查询表")
    public ResponseMsg<List<TableMeta>> getTableList(
            @ApiParam(value = "数据源ID", name = "datasourceId") @RequestParam String datasourceId) {
        ResponseMsg<List<TableMeta>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.dgsDsService.getTableList(datasourceId));

        return responseMsg;
    }

    /**
     * 根据数据源ID和表名称查询字段信息
     * @param datasourceId 数据源ID
     * @param tableName 表名称
     * @return
     */
    @GetMapping("/columnList")
    @ApiOperation(value = "根据数据源ID和表名称查询字段信息")
    public ResponseMsg<List<ColumnMeta>> getColumnList(
            @ApiParam(value = "数据源ID", name = "datasourceId") @RequestParam String datasourceId,
            @ApiParam(value = "表名称", name = "tableName") @RequestParam String tableName) {
        ResponseMsg<List<ColumnMeta>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.dgsDsService.getColumnList(datasourceId, tableName));

        return responseMsg;
    }
}
